package com.fwmagic.spark.core.cases.threadsafe

import java.text.SimpleDateFormat
import java.util.Date
import org.apache.commons.lang3.time.FastDateFormat

object DateUtils extends Serializable {

    /*线程不安全的*/
    val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

    /*线程安全的*/
    val sdf2 = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss")

    def getTime(date: String): Long = synchronized{
        val time: Date = sdf.parse(date)
        time.getTime
    }

    def getTime2(date: String): Long = synchronized{
        val time: Date = sdf2.parse(date)
        time.getTime
    }
}
